﻿using HCore;

namespace MEat
{
    public class MoveCommand : Command
    {
        private Vector3 _target;

        public MoveCommand() : base(CommandType.Move)
        {
        }

        public void SetTarget(Vector3 target)
        {
            _target = target;
        }

        public override void Write(OutputMemeryBitStream output)
        {
            base.Write(output);
            output.WriteFix(_target.x);
            output.WriteFix(_target.y);
            output.WriteFix(_target.z);
        }

        public override void Read(InputMemoryBitStream input)
        {
            base.Read(input);
            _target.x = input.ReadFix();
            _target.y = input.ReadFix();
            _target.z = input.ReadFix();
        }

        public override void ProcessCommand(HGame game)
        {
            var entityMap = game.entityMgr.entityMap;
            foreach (var kv in entityMap)
            {
                BaseGameEntity entity = kv.Value;
                if (entity is Dummy dummy)
                {
                    if (dummy.playerId != playerId)
                    {
                        return;
                    }

                    dummy.SetTarget(_target);
                }
            }
        }
    }
}